biplotEZ

User-friendly biplots in R


Centre for Multi-Dimensional Data Visualisation (MuViSU)
muvisu@sun.ac.za


StatCon 2023

2023-09-02

Outline

  • Session 1: Introduction to biplots
    • Introduction to biplots
    • PCA biplot
    • Getting started: biplotEZ
  • Session 2: Other types of biplots
    • Canonical Variate Analysis biplots
    • CVA biplot with biplotEZ

Introduction

  • The biplot is a powerful and very useful data visualisation tool. Biplots make information in a table of data become transparent, revealing the main structures in the data in a methodical way, for example patterns of correlations between variables or similarities between the observations.
  • Consider an \(n\) x \(p\) data matrix containing numerical information on \(p\) variables for each of \(n\) samples.
  • The \(n\) samples can be represented in a two-dimensional scatter diagram, where the coordinate axes can represent any two variables.
  • Samples can also be represented in a three-dimensional diagram developed from Cartesian geometry and conceptually in multidimensional forms in which there are many coordinate axes to represent the \(n\) samples.

Scatterplot of 2 variables

Biplots

  • Although two-dimensional scatter diagrams are crucial for presenting data, multidimensional scatter diagrams tend not to be.
  • Statisticians therefore, developed methods for approximating multidimensional scatter diagrams into a biplot.
  • A biplot is a generalisation of a two-dimensional scatter diagram of data that exists in a higher dimensional space, where information on both samples and variables can be displayed graphically.
  • Gabriel (1971) introduced the biplot in which the samples are represented as \(n\) points and the variables are represented as \(p\) vectors relative to the same axes and origin.

Iris data

library(tibble)
tibble(iris)
# # A tibble: 150 × 5
#    Sepal.Length Sepal.Width Petal.Length
#           <dbl>       <dbl>        <dbl>
#  1          5.1         3.5          1.4
#  2          4.9         3            1.4
#  3          4.7         3.2          1.3
#  4          4.6         3.1          1.5
#  5          5           3.6          1.4
#  6          5.4         3.9          1.7
#  7          4.6         3.4          1.4
#  8          5           3.4          1.5
#  9          4.4         2.9          1.4
# 10          4.9         3.1          1.5
# # ℹ 140 more rows
# # ℹ 2 more variables: Petal.Width <dbl>,
# #   Species <fct>
summary(iris)
#   Sepal.Length  Sepal.Width   Petal.Length  Petal.Width        Species  
#  Min.   :4.3   Min.   :2.0   Min.   :1.0   Min.   :0.1   setosa    :50  
#  1st Qu.:5.1   1st Qu.:2.8   1st Qu.:1.6   1st Qu.:0.3   versicolor:50  
#  Median :5.8   Median :3.0   Median :4.3   Median :1.3   virginica :50  
#  Mean   :5.8   Mean   :3.1   Mean   :3.8   Mean   :1.2                  
#  3rd Qu.:6.4   3rd Qu.:3.3   3rd Qu.:5.1   3rd Qu.:1.8                  
#  Max.   :7.9   Max.   :4.4   Max.   :6.9   Max.   :2.5

Biplot of Iris data

library(biplotEZ)
library(magrittr)
biplot(iris[,1:4],iris[,5]) |> PCA() |> plot()

Biplots

Considerations

  • the types of variables (quantitative, qualitative, ordinal, etc.);
  • the method used for displaying samples;
  • what the biplot will display, either for predicting a sample point or interpolating a new sample point.

For now the focus will be on (1) continuous data, (2) the method used to display samples through approximations of the data, and (3) predicting samples.

Constructing a biplot

Data: \({\bf{X}}\)

#     X1  X2   X3
# 1  5.4 5.1  8.7
# 2  3.1 1.8  3.4
# 3  6.1 2.2  8.2
# 4  6.8 4.8  8.7
# 5  7.3 5.9 11.3
# 6  7.2 3.7 10.1
# 7  7.0 5.2  8.6
# 8  5.5 4.5  5.6
# 9  7.7 4.7 11.4
# 10 7.1 5.0  7.7
# 11 8.1 4.4  9.3
# 12 6.3 5.9  7.5
# 13 4.6 7.2  8.6
# 14 5.8 6.1  8.3
# 15 8.1 3.2  9.0
# 16 6.2 5.7  9.9
# 17 3.6 2.0  3.8
# 18 7.0 2.5  9.3
# 19 7.7 5.4  9.9
# 20 8.3 6.7 12.8
# 21 8.2 4.3 11.4
# 22 8.0 5.9  9.8
# 23 6.2 5.1  6.4
# 24 8.8 5.4 12.9
# 25 8.1 5.7  8.8

Constructing a biplot

Geometrically the rows of \({\bf{X}}\) are given as coordinates of \(n\) samples in the \(p\)-dimensional space \(\mathbb{R}^p\).

The aim is to seek an \(r\)-dimensional plane that contains the points whose coordinates are given by the rows of \({\bf{\hat{X}}}_{[r]}\) which minimises a least squares criterion given by, \[\begin{equation} || {\bf{X}} - {\bf{\hat{X}}}_{[r]}||^2 = tr\{({\bf{X}} - {\bf{\hat{X}}}_{[r]})({\bf{X}} - {\bf{\hat{X}}}_{[r]})'\}. \end{equation}\]

The best approximation that minimises the least squares criterion is the \(r\)-dimensional Eckart-Young approximation given by \({\bf{\hat{X}}}_{[r]} = {\bf{U}} {\bf{D}}_{[r]} {\bf{V}}'\)

Representing samples

A standard result when \(r=2\) from is that the row vectors of \({\bf{\hat{X}}}_{[2]}\) are the orthogonal projections of the corresponding row vectors of \({\bf{X}}\) onto the column space of \({\bf{V}}_2\). The projections are therefore,

\[\begin{equation} {\bf{X}} {\bf{V}}_2. \end{equation}\] These projections are also known as the first two principal components.

Representing variables

The columns of \({\bf{X}}\) are approximated by the first two rows of \({\bf{V}}\), which now represent the axes for each variable.

Calibrated biplot axes

We have constructed a biplot, but the variables represented by the vectors (arrows) have no calibration.

That meaning, there are no markers on the vectors representing the variables analogous to ordinary scatterplots.

To construct a biplot axis with relevant markers for a variable, a \((p-1)\)-dimensional hyperplane \(\mathscr{N}\) perpendicular to the Cartesian axis is required.

First plane

From the data, \(p = 3\) therefore, a two-dimensional hyperplane is constructed perpendicular to \(X_1\) through a specific value of \(X_1\), say \(\mu\).

The intersection of \(\mathscr{L}\) and \(\mathscr{N}\) is an \((r-1)\)-dimensional intersection space, which in this case will be indicated by a line. All the points on this intersection line in \(\mathscr{L}\) will predict the value for \(\mu\) for the \(X_1\)-axis.

Second plane

The plane \(\mathscr{N}\) is shifted orthogonally through another value on \(X_1\) and all the points on the intersection line of \(\mathscr{L}\) and \(\mathscr{N}\) will predict that value that the plane goes through.

Intersection lines

As the plane \(\mathscr{N}\) is shifted along the \(X_1\)-axis, a series of parallel intersection spaces is obtained.

Any line passing through the origin will pass through these intersection spaces and can be used as an axis fitted with markers according to the value associated with the particular intersection space.

To facilitate orthogonal projection onto the axis, similar to an ordinary scatterplot, the line orthogonal to these intersection spaces is chosen.

PCA Biplot

biplot(X) |> PCA() |> plot()

Installing biplotEZ

# Install from GitHub
library(devtools)
install_github("MuViSU/biplotEZ_beta")
#check this
library(biplotEZ)
#check this
library(biplotEZ_beta)

# Getting help                 
help(package="biplotEZ")

General notes

  • Use the native R pipe: |>
  • Since %>% is not required, you do not have to load:
library(magrittr)
  • To set |> as your default, change the keyboard shortcut Ctrl-Shift-M:

Global options

Global options

Functions in current version

  • Use the following function to obtain a list of available functions in a package: \(~\)
lsf.str("package:biplotEZ")
# alpha.bags : function (bp, alpha = 0.95, which = NULL, col = ez.col, lty = 1, lwd = 1, max = 2500)  
# axes : function (bp, X.names = colnames(bp$X), which = 1:bp$p, col = grey(0.7), lwd = 1, lty = 1, label.dir = "Orthog", 
#     label.col = col, label.cex = 0.75, label.dist = 0, ticks = 5, tick.col = col, tick.size = 1, tick.label = T, 
#     tick.label.col = tick.col, tick.label.cex = 0.6, tick.label.side = "left", tick.label.offset = 0.5, tick.label.pos = 1, 
#     predict.col = col, predict.lwd = lwd, predict.lty = lty, ax.names = X.names, orthogx = 0, orthogy = 0)  
# biplot : function (data, group.aes = NULL, center = TRUE, scaled = FALSE, Title = NULL)  
# concentration.ellipse : function (bp, df = 2, kappa = NULL, which = NULL, alpha = 0.95, col = ez.col, lty = 1, lwd = 1, alpha.transparency = 0.5)  
# legend.type : function (bp, samples = F, means = F, bags = F, new = FALSE, ...)  
# PCA : function (bp, dim.biplot = c(2, 1, 3), e.vects = 1:ncol(bp$X), group.aes = NULL, correlation.biplot = FALSE, ...)  
# samples : function (bp, col = ez.col, pch = 3, cex = 1, label = F, label.cex = 0.75, label.side = "bottom", connected = F, 
#     alpha = 1)

Flow of functions

  • Start with biplot()
    • Use the preferred biplot: PCA() and CVA() available in current version
    • Format samples() and axes()
    • Add alpha.bags() or concentration.ellipse()
    • Add a legend.type()
  • End with plot()

Use pipe ( |> ) between each subsequent function. The order in which functions are applied between biplot() and plot() does not make a difference.

Simple example for PCA biplot

biplot(iris[,1:4]) |> PCA() |> samples(col="purple",pch=15) |>  plot()

First step: biplot()

# function (data, group.aes = NULL, center = TRUE, scaled = FALSE, 
#     Title = NULL) 
# NULL
Argument Description
data A dataframe or matrix containing all variables the user wants to analyse.
group.aes Variable from the data to be used as a grouping variable.
center TRUE or FALSE
scaled TRUE or FALSE
Title Title of the biplot to be rendered.

First step: biplot() - Example

biplot(data = iris)
# $X
#     Sepal.Length Sepal.Width Petal.Length Petal.Width
# 1         -0.743       0.443       -2.358    -0.99933
# 2         -0.943      -0.057       -2.358    -0.99933
# 3         -1.143       0.143       -2.458    -0.99933
# 4         -1.243       0.043       -2.258    -0.99933
# 5         -0.843       0.543       -2.358    -0.99933
# 6         -0.443       0.843       -2.058    -0.79933
# 7         -1.243       0.343       -2.358    -0.89933
# 8         -0.843       0.343       -2.258    -0.99933
# 9         -1.443      -0.157       -2.358    -0.99933
# 10        -0.943       0.043       -2.258    -1.09933
# 11        -0.443       0.643       -2.258    -0.99933
# 12        -1.043       0.343       -2.158    -0.99933
# 13        -1.043      -0.057       -2.358    -1.09933
# 14        -1.543      -0.057       -2.658    -1.09933
# 15        -0.043       0.943       -2.558    -0.99933
# 16        -0.143       1.343       -2.258    -0.79933
# 17        -0.443       0.843       -2.458    -0.79933
# 18        -0.743       0.443       -2.358    -0.89933
# 19        -0.143       0.743       -2.058    -0.89933
# 20        -0.743       0.743       -2.258    -0.89933
# 21        -0.443       0.343       -2.058    -0.99933
# 22        -0.743       0.643       -2.258    -0.79933
# 23        -1.243       0.543       -2.758    -0.99933
# 24        -0.743       0.243       -2.058    -0.69933
# 25        -1.043       0.343       -1.858    -0.99933
# 26        -0.843      -0.057       -2.158    -0.99933
# 27        -0.843       0.343       -2.158    -0.79933
# 28        -0.643       0.443       -2.258    -0.99933
# 29        -0.643       0.343       -2.358    -0.99933
# 30        -1.143       0.143       -2.158    -0.99933
# 31        -1.043       0.043       -2.158    -0.99933
# 32        -0.443       0.343       -2.258    -0.79933
# 33        -0.643       1.043       -2.258    -1.09933
# 34        -0.343       1.143       -2.358    -0.99933
# 35        -0.943       0.043       -2.258    -0.99933
# 36        -0.843       0.143       -2.558    -0.99933
# 37        -0.343       0.443       -2.458    -0.99933
# 38        -0.943       0.543       -2.358    -1.09933
# 39        -1.443      -0.057       -2.458    -0.99933
# 40        -0.743       0.343       -2.258    -0.99933
# 41        -0.843       0.443       -2.458    -0.89933
# 42        -1.343      -0.757       -2.458    -0.89933
# 43        -1.443       0.143       -2.458    -0.99933
# 44        -0.843       0.443       -2.158    -0.59933
# 45        -0.743       0.743       -1.858    -0.79933
# 46        -1.043      -0.057       -2.358    -0.89933
# 47        -0.743       0.743       -2.158    -0.99933
# 48        -1.243       0.143       -2.358    -0.99933
# 49        -0.543       0.643       -2.258    -0.99933
# 50        -0.843       0.243       -2.358    -0.99933
# 51         1.157       0.143        0.942     0.20067
# 52         0.557       0.143        0.742     0.30067
# 53         1.057       0.043        1.142     0.30067
# 54        -0.343      -0.757        0.242     0.10067
# 55         0.657      -0.257        0.842     0.30067
# 56        -0.143      -0.257        0.742     0.10067
# 57         0.457       0.243        0.942     0.40067
# 58        -0.943      -0.657       -0.458    -0.19933
# 59         0.757      -0.157        0.842     0.10067
# 60        -0.643      -0.357        0.142     0.20067
# 61        -0.843      -1.057       -0.258    -0.19933
# 62         0.057      -0.057        0.442     0.30067
# 63         0.157      -0.857        0.242    -0.19933
# 64         0.257      -0.157        0.942     0.20067
# 65        -0.243      -0.157       -0.158     0.10067
# 66         0.857       0.043        0.642     0.20067
# 67        -0.243      -0.057        0.742     0.30067
# 68        -0.043      -0.357        0.342    -0.19933
# 69         0.357      -0.857        0.742     0.30067
# 70        -0.243      -0.557        0.142    -0.09933
# 71         0.057       0.143        1.042     0.60067
# 72         0.257      -0.257        0.242     0.10067
# 73         0.457      -0.557        1.142     0.30067
# 74         0.257      -0.257        0.942     0.00067
# 75         0.557      -0.157        0.542     0.10067
# 76         0.757      -0.057        0.642     0.20067
# 77         0.957      -0.257        1.042     0.20067
# 78         0.857      -0.057        1.242     0.50067
# 79         0.157      -0.157        0.742     0.30067
# 80        -0.143      -0.457       -0.258    -0.19933
# 81        -0.343      -0.657        0.042    -0.09933
# 82        -0.343      -0.657       -0.058    -0.19933
# 83        -0.043      -0.357        0.142     0.00067
# 84         0.157      -0.357        1.342     0.40067
# 85        -0.443      -0.057        0.742     0.30067
# 86         0.157       0.343        0.742     0.40067
# 87         0.857       0.043        0.942     0.30067
# 88         0.457      -0.757        0.642     0.10067
# 89        -0.243      -0.057        0.342     0.10067
# 90        -0.343      -0.557        0.242     0.10067
# 91        -0.343      -0.457        0.642     0.00067
# 92         0.257      -0.057        0.842     0.20067
# 93        -0.043      -0.457        0.242     0.00067
# 94        -0.843      -0.757       -0.458    -0.19933
# 95        -0.243      -0.357        0.442     0.10067
# 96        -0.143      -0.057        0.442     0.00067
# 97        -0.143      -0.157        0.442     0.10067
# 98         0.357      -0.157        0.542     0.10067
# 99        -0.743      -0.557       -0.758    -0.09933
# 100       -0.143      -0.257        0.342     0.10067
# 101        0.457       0.243        2.242     1.30067
# 102       -0.043      -0.357        1.342     0.70067
# 103        1.257      -0.057        2.142     0.90067
# 104        0.457      -0.157        1.842     0.60067
# 105        0.657      -0.057        2.042     1.00067
# 106        1.757      -0.057        2.842     0.90067
# 107       -0.943      -0.557        0.742     0.50067
# 108        1.457      -0.157        2.542     0.60067
# 109        0.857      -0.557        2.042     0.60067
# 110        1.357       0.543        2.342     1.30067
# 111        0.657       0.143        1.342     0.80067
# 112        0.557      -0.357        1.542     0.70067
# 113        0.957      -0.057        1.742     0.90067
# 114       -0.143      -0.557        1.242     0.80067
# 115       -0.043      -0.257        1.342     1.20067
# 116        0.557       0.143        1.542     1.10067
# 117        0.657      -0.057        1.742     0.60067
# 118        1.857       0.743        2.942     1.00067
# 119        1.857      -0.457        3.142     1.10067
# 120        0.157      -0.857        1.242     0.30067
# 121        1.057       0.143        1.942     1.10067
# 122       -0.243      -0.257        1.142     0.80067
# 123        1.857      -0.257        2.942     0.80067
# 124        0.457      -0.357        1.142     0.60067
# 125        0.857       0.243        1.942     0.90067
# 126        1.357       0.143        2.242     0.60067
# 127        0.357      -0.257        1.042     0.60067
# 128        0.257      -0.057        1.142     0.60067
# 129        0.557      -0.257        1.842     0.90067
# 130        1.357      -0.057        2.042     0.40067
# 131        1.557      -0.257        2.342     0.70067
# 132        2.057       0.743        2.642     0.80067
# 133        0.557      -0.257        1.842     1.00067
# 134        0.457      -0.257        1.342     0.30067
# 135        0.257      -0.457        1.842     0.20067
# 136        1.857      -0.057        2.342     1.10067
# 137        0.457       0.343        1.842     1.20067
# 138        0.557       0.043        1.742     0.60067
# 139        0.157      -0.057        1.042     0.60067
# 140        1.057       0.043        1.642     0.90067
# 141        0.857       0.043        1.842     1.20067
# 142        1.057       0.043        1.342     1.10067
# 143       -0.043      -0.357        1.342     0.70067
# 144        0.957       0.143        2.142     1.10067
# 145        0.857       0.243        1.942     1.30067
# 146        0.857      -0.057        1.442     1.10067
# 147        0.457      -0.557        1.242     0.70067
# 148        0.657      -0.057        1.442     0.80067
# 149        0.357       0.343        1.642     1.10067
# 150        0.057      -0.057        1.342     0.60067
# attr(,"scaled:center")
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#          5.8          3.1          3.8          1.2 
# 
# $Xcat
#        Species
# 1       setosa
# 2       setosa
# 3       setosa
# 4       setosa
# 5       setosa
# 6       setosa
# 7       setosa
# 8       setosa
# 9       setosa
# 10      setosa
# 11      setosa
# 12      setosa
# 13      setosa
# 14      setosa
# 15      setosa
# 16      setosa
# 17      setosa
# 18      setosa
# 19      setosa
# 20      setosa
# 21      setosa
# 22      setosa
# 23      setosa
# 24      setosa
# 25      setosa
# 26      setosa
# 27      setosa
# 28      setosa
# 29      setosa
# 30      setosa
# 31      setosa
# 32      setosa
# 33      setosa
# 34      setosa
# 35      setosa
# 36      setosa
# 37      setosa
# 38      setosa
# 39      setosa
# 40      setosa
# 41      setosa
# 42      setosa
# 43      setosa
# 44      setosa
# 45      setosa
# 46      setosa
# 47      setosa
# 48      setosa
# 49      setosa
# 50      setosa
# 51  versicolor
# 52  versicolor
# 53  versicolor
# 54  versicolor
# 55  versicolor
# 56  versicolor
# 57  versicolor
# 58  versicolor
# 59  versicolor
# 60  versicolor
# 61  versicolor
# 62  versicolor
# 63  versicolor
# 64  versicolor
# 65  versicolor
# 66  versicolor
# 67  versicolor
# 68  versicolor
# 69  versicolor
# 70  versicolor
# 71  versicolor
# 72  versicolor
# 73  versicolor
# 74  versicolor
# 75  versicolor
# 76  versicolor
# 77  versicolor
# 78  versicolor
# 79  versicolor
# 80  versicolor
# 81  versicolor
# 82  versicolor
# 83  versicolor
# 84  versicolor
# 85  versicolor
# 86  versicolor
# 87  versicolor
# 88  versicolor
# 89  versicolor
# 90  versicolor
# 91  versicolor
# 92  versicolor
# 93  versicolor
# 94  versicolor
# 95  versicolor
# 96  versicolor
# 97  versicolor
# 98  versicolor
# 99  versicolor
# 100 versicolor
# 101  virginica
# 102  virginica
# 103  virginica
# 104  virginica
# 105  virginica
# 106  virginica
# 107  virginica
# 108  virginica
# 109  virginica
# 110  virginica
# 111  virginica
# 112  virginica
# 113  virginica
# 114  virginica
# 115  virginica
# 116  virginica
# 117  virginica
# 118  virginica
# 119  virginica
# 120  virginica
# 121  virginica
# 122  virginica
# 123  virginica
# 124  virginica
# 125  virginica
# 126  virginica
# 127  virginica
# 128  virginica
# 129  virginica
# 130  virginica
# 131  virginica
# 132  virginica
# 133  virginica
# 134  virginica
# 135  virginica
# 136  virginica
# 137  virginica
# 138  virginica
# 139  virginica
# 140  virginica
# 141  virginica
# 142  virginica
# 143  virginica
# 144  virginica
# 145  virginica
# 146  virginica
# 147  virginica
# 148  virginica
# 149  virginica
# 150  virginica
# 
# $raw.X
#     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
# 1            5.1         3.5          1.4         0.2     setosa
# 2            4.9         3.0          1.4         0.2     setosa
# 3            4.7         3.2          1.3         0.2     setosa
# 4            4.6         3.1          1.5         0.2     setosa
# 5            5.0         3.6          1.4         0.2     setosa
# 6            5.4         3.9          1.7         0.4     setosa
# 7            4.6         3.4          1.4         0.3     setosa
# 8            5.0         3.4          1.5         0.2     setosa
# 9            4.4         2.9          1.4         0.2     setosa
# 10           4.9         3.1          1.5         0.1     setosa
# 11           5.4         3.7          1.5         0.2     setosa
# 12           4.8         3.4          1.6         0.2     setosa
# 13           4.8         3.0          1.4         0.1     setosa
# 14           4.3         3.0          1.1         0.1     setosa
# 15           5.8         4.0          1.2         0.2     setosa
# 16           5.7         4.4          1.5         0.4     setosa
# 17           5.4         3.9          1.3         0.4     setosa
# 18           5.1         3.5          1.4         0.3     setosa
# 19           5.7         3.8          1.7         0.3     setosa
# 20           5.1         3.8          1.5         0.3     setosa
# 21           5.4         3.4          1.7         0.2     setosa
# 22           5.1         3.7          1.5         0.4     setosa
# 23           4.6         3.6          1.0         0.2     setosa
# 24           5.1         3.3          1.7         0.5     setosa
# 25           4.8         3.4          1.9         0.2     setosa
# 26           5.0         3.0          1.6         0.2     setosa
# 27           5.0         3.4          1.6         0.4     setosa
# 28           5.2         3.5          1.5         0.2     setosa
# 29           5.2         3.4          1.4         0.2     setosa
# 30           4.7         3.2          1.6         0.2     setosa
# 31           4.8         3.1          1.6         0.2     setosa
# 32           5.4         3.4          1.5         0.4     setosa
# 33           5.2         4.1          1.5         0.1     setosa
# 34           5.5         4.2          1.4         0.2     setosa
# 35           4.9         3.1          1.5         0.2     setosa
# 36           5.0         3.2          1.2         0.2     setosa
# 37           5.5         3.5          1.3         0.2     setosa
# 38           4.9         3.6          1.4         0.1     setosa
# 39           4.4         3.0          1.3         0.2     setosa
# 40           5.1         3.4          1.5         0.2     setosa
# 41           5.0         3.5          1.3         0.3     setosa
# 42           4.5         2.3          1.3         0.3     setosa
# 43           4.4         3.2          1.3         0.2     setosa
# 44           5.0         3.5          1.6         0.6     setosa
# 45           5.1         3.8          1.9         0.4     setosa
# 46           4.8         3.0          1.4         0.3     setosa
# 47           5.1         3.8          1.6         0.2     setosa
# 48           4.6         3.2          1.4         0.2     setosa
# 49           5.3         3.7          1.5         0.2     setosa
# 50           5.0         3.3          1.4         0.2     setosa
# 51           7.0         3.2          4.7         1.4 versicolor
# 52           6.4         3.2          4.5         1.5 versicolor
# 53           6.9         3.1          4.9         1.5 versicolor
# 54           5.5         2.3          4.0         1.3 versicolor
# 55           6.5         2.8          4.6         1.5 versicolor
# 56           5.7         2.8          4.5         1.3 versicolor
# 57           6.3         3.3          4.7         1.6 versicolor
# 58           4.9         2.4          3.3         1.0 versicolor
# 59           6.6         2.9          4.6         1.3 versicolor
# 60           5.2         2.7          3.9         1.4 versicolor
# 61           5.0         2.0          3.5         1.0 versicolor
# 62           5.9         3.0          4.2         1.5 versicolor
# 63           6.0         2.2          4.0         1.0 versicolor
# 64           6.1         2.9          4.7         1.4 versicolor
# 65           5.6         2.9          3.6         1.3 versicolor
# 66           6.7         3.1          4.4         1.4 versicolor
# 67           5.6         3.0          4.5         1.5 versicolor
# 68           5.8         2.7          4.1         1.0 versicolor
# 69           6.2         2.2          4.5         1.5 versicolor
# 70           5.6         2.5          3.9         1.1 versicolor
# 71           5.9         3.2          4.8         1.8 versicolor
# 72           6.1         2.8          4.0         1.3 versicolor
# 73           6.3         2.5          4.9         1.5 versicolor
# 74           6.1         2.8          4.7         1.2 versicolor
# 75           6.4         2.9          4.3         1.3 versicolor
# 76           6.6         3.0          4.4         1.4 versicolor
# 77           6.8         2.8          4.8         1.4 versicolor
# 78           6.7         3.0          5.0         1.7 versicolor
# 79           6.0         2.9          4.5         1.5 versicolor
# 80           5.7         2.6          3.5         1.0 versicolor
# 81           5.5         2.4          3.8         1.1 versicolor
# 82           5.5         2.4          3.7         1.0 versicolor
# 83           5.8         2.7          3.9         1.2 versicolor
# 84           6.0         2.7          5.1         1.6 versicolor
# 85           5.4         3.0          4.5         1.5 versicolor
# 86           6.0         3.4          4.5         1.6 versicolor
# 87           6.7         3.1          4.7         1.5 versicolor
# 88           6.3         2.3          4.4         1.3 versicolor
# 89           5.6         3.0          4.1         1.3 versicolor
# 90           5.5         2.5          4.0         1.3 versicolor
# 91           5.5         2.6          4.4         1.2 versicolor
# 92           6.1         3.0          4.6         1.4 versicolor
# 93           5.8         2.6          4.0         1.2 versicolor
# 94           5.0         2.3          3.3         1.0 versicolor
# 95           5.6         2.7          4.2         1.3 versicolor
# 96           5.7         3.0          4.2         1.2 versicolor
# 97           5.7         2.9          4.2         1.3 versicolor
# 98           6.2         2.9          4.3         1.3 versicolor
# 99           5.1         2.5          3.0         1.1 versicolor
# 100          5.7         2.8          4.1         1.3 versicolor
# 101          6.3         3.3          6.0         2.5  virginica
# 102          5.8         2.7          5.1         1.9  virginica
# 103          7.1         3.0          5.9         2.1  virginica
# 104          6.3         2.9          5.6         1.8  virginica
# 105          6.5         3.0          5.8         2.2  virginica
# 106          7.6         3.0          6.6         2.1  virginica
# 107          4.9         2.5          4.5         1.7  virginica
# 108          7.3         2.9          6.3         1.8  virginica
# 109          6.7         2.5          5.8         1.8  virginica
# 110          7.2         3.6          6.1         2.5  virginica
# 111          6.5         3.2          5.1         2.0  virginica
# 112          6.4         2.7          5.3         1.9  virginica
# 113          6.8         3.0          5.5         2.1  virginica
# 114          5.7         2.5          5.0         2.0  virginica
# 115          5.8         2.8          5.1         2.4  virginica
# 116          6.4         3.2          5.3         2.3  virginica
# 117          6.5         3.0          5.5         1.8  virginica
# 118          7.7         3.8          6.7         2.2  virginica
# 119          7.7         2.6          6.9         2.3  virginica
# 120          6.0         2.2          5.0         1.5  virginica
# 121          6.9         3.2          5.7         2.3  virginica
# 122          5.6         2.8          4.9         2.0  virginica
# 123          7.7         2.8          6.7         2.0  virginica
# 124          6.3         2.7          4.9         1.8  virginica
# 125          6.7         3.3          5.7         2.1  virginica
# 126          7.2         3.2          6.0         1.8  virginica
# 127          6.2         2.8          4.8         1.8  virginica
# 128          6.1         3.0          4.9         1.8  virginica
# 129          6.4         2.8          5.6         2.1  virginica
# 130          7.2         3.0          5.8         1.6  virginica
# 131          7.4         2.8          6.1         1.9  virginica
# 132          7.9         3.8          6.4         2.0  virginica
# 133          6.4         2.8          5.6         2.2  virginica
# 134          6.3         2.8          5.1         1.5  virginica
# 135          6.1         2.6          5.6         1.4  virginica
# 136          7.7         3.0          6.1         2.3  virginica
# 137          6.3         3.4          5.6         2.4  virginica
# 138          6.4         3.1          5.5         1.8  virginica
# 139          6.0         3.0          4.8         1.8  virginica
# 140          6.9         3.1          5.4         2.1  virginica
# 141          6.7         3.1          5.6         2.4  virginica
# 142          6.9         3.1          5.1         2.3  virginica
# 143          5.8         2.7          5.1         1.9  virginica
# 144          6.8         3.2          5.9         2.3  virginica
# 145          6.7         3.3          5.7         2.5  virginica
# 146          6.7         3.0          5.2         2.3  virginica
# 147          6.3         2.5          5.0         1.9  virginica
# 148          6.5         3.0          5.2         2.0  virginica
# 149          6.2         3.4          5.4         2.3  virginica
# 150          5.9         3.0          5.1         1.8  virginica
# 
# $na.action
# NULL
# 
# $center
# [1] TRUE
# 
# $scaled
# [1] FALSE
# 
# $means
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#          5.8          3.1          3.8          1.2 
# 
# $sd
# [1] 1 1 1 1
# 
# $n
# [1] 150
# 
# $p
# [1] 4
# 
# $group.aes
#   [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#  [58] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# [115] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# Levels: 1
# 
# $g.names
# [1] "1"
# 
# $g
# [1] 1
# 
# $Title
# NULL
# 
# attr(,"class")
# [1] "biplot"

Step 2: PCA()

# function (bp, dim.biplot = c(2, 1, 3), e.vects = 1:ncol(bp$X), 
#     group.aes = NULL, correlation.biplot = FALSE, ...) 
# NULL
Argument Description
bp Object of class PCA.
dim.biplot Dimension of the biplot. Only values 1, 2 and 3 are accepted, with default 2.
e.vects Which eigenvectors (principal components) to extract, with default 1:dim.biplot.

Step 2: PCA() - continues

# function (bp, dim.biplot = c(2, 1, 3), e.vects = 1:ncol(bp$X), 
#     group.aes = NULL, correlation.biplot = FALSE, ...) 
# NULL
Argument Description
group.aes Optional vector of the same length as the number of rows in the data matrix for differentiated aesthetics for samples.
correlation.biplot If FALSE, the distances between sample points are optimally approximated in the biplot. If TRUE, the correlations between variables are optimally approximated by the cosine of the angles between axes. Deafult is FALSE.

Step 2: PCA() - Example

biplot(iris[,1:4]) |> PCA()
# $X
#     Sepal.Length Sepal.Width Petal.Length Petal.Width
# 1         -0.743       0.443       -2.358    -0.99933
# 2         -0.943      -0.057       -2.358    -0.99933
# 3         -1.143       0.143       -2.458    -0.99933
# 4         -1.243       0.043       -2.258    -0.99933
# 5         -0.843       0.543       -2.358    -0.99933
# 6         -0.443       0.843       -2.058    -0.79933
# 7         -1.243       0.343       -2.358    -0.89933
# 8         -0.843       0.343       -2.258    -0.99933
# 9         -1.443      -0.157       -2.358    -0.99933
# 10        -0.943       0.043       -2.258    -1.09933
# 11        -0.443       0.643       -2.258    -0.99933
# 12        -1.043       0.343       -2.158    -0.99933
# 13        -1.043      -0.057       -2.358    -1.09933
# 14        -1.543      -0.057       -2.658    -1.09933
# 15        -0.043       0.943       -2.558    -0.99933
# 16        -0.143       1.343       -2.258    -0.79933
# 17        -0.443       0.843       -2.458    -0.79933
# 18        -0.743       0.443       -2.358    -0.89933
# 19        -0.143       0.743       -2.058    -0.89933
# 20        -0.743       0.743       -2.258    -0.89933
# 21        -0.443       0.343       -2.058    -0.99933
# 22        -0.743       0.643       -2.258    -0.79933
# 23        -1.243       0.543       -2.758    -0.99933
# 24        -0.743       0.243       -2.058    -0.69933
# 25        -1.043       0.343       -1.858    -0.99933
# 26        -0.843      -0.057       -2.158    -0.99933
# 27        -0.843       0.343       -2.158    -0.79933
# 28        -0.643       0.443       -2.258    -0.99933
# 29        -0.643       0.343       -2.358    -0.99933
# 30        -1.143       0.143       -2.158    -0.99933
# 31        -1.043       0.043       -2.158    -0.99933
# 32        -0.443       0.343       -2.258    -0.79933
# 33        -0.643       1.043       -2.258    -1.09933
# 34        -0.343       1.143       -2.358    -0.99933
# 35        -0.943       0.043       -2.258    -0.99933
# 36        -0.843       0.143       -2.558    -0.99933
# 37        -0.343       0.443       -2.458    -0.99933
# 38        -0.943       0.543       -2.358    -1.09933
# 39        -1.443      -0.057       -2.458    -0.99933
# 40        -0.743       0.343       -2.258    -0.99933
# 41        -0.843       0.443       -2.458    -0.89933
# 42        -1.343      -0.757       -2.458    -0.89933
# 43        -1.443       0.143       -2.458    -0.99933
# 44        -0.843       0.443       -2.158    -0.59933
# 45        -0.743       0.743       -1.858    -0.79933
# 46        -1.043      -0.057       -2.358    -0.89933
# 47        -0.743       0.743       -2.158    -0.99933
# 48        -1.243       0.143       -2.358    -0.99933
# 49        -0.543       0.643       -2.258    -0.99933
# 50        -0.843       0.243       -2.358    -0.99933
# 51         1.157       0.143        0.942     0.20067
# 52         0.557       0.143        0.742     0.30067
# 53         1.057       0.043        1.142     0.30067
# 54        -0.343      -0.757        0.242     0.10067
# 55         0.657      -0.257        0.842     0.30067
# 56        -0.143      -0.257        0.742     0.10067
# 57         0.457       0.243        0.942     0.40067
# 58        -0.943      -0.657       -0.458    -0.19933
# 59         0.757      -0.157        0.842     0.10067
# 60        -0.643      -0.357        0.142     0.20067
# 61        -0.843      -1.057       -0.258    -0.19933
# 62         0.057      -0.057        0.442     0.30067
# 63         0.157      -0.857        0.242    -0.19933
# 64         0.257      -0.157        0.942     0.20067
# 65        -0.243      -0.157       -0.158     0.10067
# 66         0.857       0.043        0.642     0.20067
# 67        -0.243      -0.057        0.742     0.30067
# 68        -0.043      -0.357        0.342    -0.19933
# 69         0.357      -0.857        0.742     0.30067
# 70        -0.243      -0.557        0.142    -0.09933
# 71         0.057       0.143        1.042     0.60067
# 72         0.257      -0.257        0.242     0.10067
# 73         0.457      -0.557        1.142     0.30067
# 74         0.257      -0.257        0.942     0.00067
# 75         0.557      -0.157        0.542     0.10067
# 76         0.757      -0.057        0.642     0.20067
# 77         0.957      -0.257        1.042     0.20067
# 78         0.857      -0.057        1.242     0.50067
# 79         0.157      -0.157        0.742     0.30067
# 80        -0.143      -0.457       -0.258    -0.19933
# 81        -0.343      -0.657        0.042    -0.09933
# 82        -0.343      -0.657       -0.058    -0.19933
# 83        -0.043      -0.357        0.142     0.00067
# 84         0.157      -0.357        1.342     0.40067
# 85        -0.443      -0.057        0.742     0.30067
# 86         0.157       0.343        0.742     0.40067
# 87         0.857       0.043        0.942     0.30067
# 88         0.457      -0.757        0.642     0.10067
# 89        -0.243      -0.057        0.342     0.10067
# 90        -0.343      -0.557        0.242     0.10067
# 91        -0.343      -0.457        0.642     0.00067
# 92         0.257      -0.057        0.842     0.20067
# 93        -0.043      -0.457        0.242     0.00067
# 94        -0.843      -0.757       -0.458    -0.19933
# 95        -0.243      -0.357        0.442     0.10067
# 96        -0.143      -0.057        0.442     0.00067
# 97        -0.143      -0.157        0.442     0.10067
# 98         0.357      -0.157        0.542     0.10067
# 99        -0.743      -0.557       -0.758    -0.09933
# 100       -0.143      -0.257        0.342     0.10067
# 101        0.457       0.243        2.242     1.30067
# 102       -0.043      -0.357        1.342     0.70067
# 103        1.257      -0.057        2.142     0.90067
# 104        0.457      -0.157        1.842     0.60067
# 105        0.657      -0.057        2.042     1.00067
# 106        1.757      -0.057        2.842     0.90067
# 107       -0.943      -0.557        0.742     0.50067
# 108        1.457      -0.157        2.542     0.60067
# 109        0.857      -0.557        2.042     0.60067
# 110        1.357       0.543        2.342     1.30067
# 111        0.657       0.143        1.342     0.80067
# 112        0.557      -0.357        1.542     0.70067
# 113        0.957      -0.057        1.742     0.90067
# 114       -0.143      -0.557        1.242     0.80067
# 115       -0.043      -0.257        1.342     1.20067
# 116        0.557       0.143        1.542     1.10067
# 117        0.657      -0.057        1.742     0.60067
# 118        1.857       0.743        2.942     1.00067
# 119        1.857      -0.457        3.142     1.10067
# 120        0.157      -0.857        1.242     0.30067
# 121        1.057       0.143        1.942     1.10067
# 122       -0.243      -0.257        1.142     0.80067
# 123        1.857      -0.257        2.942     0.80067
# 124        0.457      -0.357        1.142     0.60067
# 125        0.857       0.243        1.942     0.90067
# 126        1.357       0.143        2.242     0.60067
# 127        0.357      -0.257        1.042     0.60067
# 128        0.257      -0.057        1.142     0.60067
# 129        0.557      -0.257        1.842     0.90067
# 130        1.357      -0.057        2.042     0.40067
# 131        1.557      -0.257        2.342     0.70067
# 132        2.057       0.743        2.642     0.80067
# 133        0.557      -0.257        1.842     1.00067
# 134        0.457      -0.257        1.342     0.30067
# 135        0.257      -0.457        1.842     0.20067
# 136        1.857      -0.057        2.342     1.10067
# 137        0.457       0.343        1.842     1.20067
# 138        0.557       0.043        1.742     0.60067
# 139        0.157      -0.057        1.042     0.60067
# 140        1.057       0.043        1.642     0.90067
# 141        0.857       0.043        1.842     1.20067
# 142        1.057       0.043        1.342     1.10067
# 143       -0.043      -0.357        1.342     0.70067
# 144        0.957       0.143        2.142     1.10067
# 145        0.857       0.243        1.942     1.30067
# 146        0.857      -0.057        1.442     1.10067
# 147        0.457      -0.557        1.242     0.70067
# 148        0.657      -0.057        1.442     0.80067
# 149        0.357       0.343        1.642     1.10067
# 150        0.057      -0.057        1.342     0.60067
# attr(,"scaled:center")
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#          5.8          3.1          3.8          1.2 
# 
# $Xcat
# NULL
# 
# $raw.X
#     Sepal.Length Sepal.Width Petal.Length Petal.Width
# 1            5.1         3.5          1.4         0.2
# 2            4.9         3.0          1.4         0.2
# 3            4.7         3.2          1.3         0.2
# 4            4.6         3.1          1.5         0.2
# 5            5.0         3.6          1.4         0.2
# 6            5.4         3.9          1.7         0.4
# 7            4.6         3.4          1.4         0.3
# 8            5.0         3.4          1.5         0.2
# 9            4.4         2.9          1.4         0.2
# 10           4.9         3.1          1.5         0.1
# 11           5.4         3.7          1.5         0.2
# 12           4.8         3.4          1.6         0.2
# 13           4.8         3.0          1.4         0.1
# 14           4.3         3.0          1.1         0.1
# 15           5.8         4.0          1.2         0.2
# 16           5.7         4.4          1.5         0.4
# 17           5.4         3.9          1.3         0.4
# 18           5.1         3.5          1.4         0.3
# 19           5.7         3.8          1.7         0.3
# 20           5.1         3.8          1.5         0.3
# 21           5.4         3.4          1.7         0.2
# 22           5.1         3.7          1.5         0.4
# 23           4.6         3.6          1.0         0.2
# 24           5.1         3.3          1.7         0.5
# 25           4.8         3.4          1.9         0.2
# 26           5.0         3.0          1.6         0.2
# 27           5.0         3.4          1.6         0.4
# 28           5.2         3.5          1.5         0.2
# 29           5.2         3.4          1.4         0.2
# 30           4.7         3.2          1.6         0.2
# 31           4.8         3.1          1.6         0.2
# 32           5.4         3.4          1.5         0.4
# 33           5.2         4.1          1.5         0.1
# 34           5.5         4.2          1.4         0.2
# 35           4.9         3.1          1.5         0.2
# 36           5.0         3.2          1.2         0.2
# 37           5.5         3.5          1.3         0.2
# 38           4.9         3.6          1.4         0.1
# 39           4.4         3.0          1.3         0.2
# 40           5.1         3.4          1.5         0.2
# 41           5.0         3.5          1.3         0.3
# 42           4.5         2.3          1.3         0.3
# 43           4.4         3.2          1.3         0.2
# 44           5.0         3.5          1.6         0.6
# 45           5.1         3.8          1.9         0.4
# 46           4.8         3.0          1.4         0.3
# 47           5.1         3.8          1.6         0.2
# 48           4.6         3.2          1.4         0.2
# 49           5.3         3.7          1.5         0.2
# 50           5.0         3.3          1.4         0.2
# 51           7.0         3.2          4.7         1.4
# 52           6.4         3.2          4.5         1.5
# 53           6.9         3.1          4.9         1.5
# 54           5.5         2.3          4.0         1.3
# 55           6.5         2.8          4.6         1.5
# 56           5.7         2.8          4.5         1.3
# 57           6.3         3.3          4.7         1.6
# 58           4.9         2.4          3.3         1.0
# 59           6.6         2.9          4.6         1.3
# 60           5.2         2.7          3.9         1.4
# 61           5.0         2.0          3.5         1.0
# 62           5.9         3.0          4.2         1.5
# 63           6.0         2.2          4.0         1.0
# 64           6.1         2.9          4.7         1.4
# 65           5.6         2.9          3.6         1.3
# 66           6.7         3.1          4.4         1.4
# 67           5.6         3.0          4.5         1.5
# 68           5.8         2.7          4.1         1.0
# 69           6.2         2.2          4.5         1.5
# 70           5.6         2.5          3.9         1.1
# 71           5.9         3.2          4.8         1.8
# 72           6.1         2.8          4.0         1.3
# 73           6.3         2.5          4.9         1.5
# 74           6.1         2.8          4.7         1.2
# 75           6.4         2.9          4.3         1.3
# 76           6.6         3.0          4.4         1.4
# 77           6.8         2.8          4.8         1.4
# 78           6.7         3.0          5.0         1.7
# 79           6.0         2.9          4.5         1.5
# 80           5.7         2.6          3.5         1.0
# 81           5.5         2.4          3.8         1.1
# 82           5.5         2.4          3.7         1.0
# 83           5.8         2.7          3.9         1.2
# 84           6.0         2.7          5.1         1.6
# 85           5.4         3.0          4.5         1.5
# 86           6.0         3.4          4.5         1.6
# 87           6.7         3.1          4.7         1.5
# 88           6.3         2.3          4.4         1.3
# 89           5.6         3.0          4.1         1.3
# 90           5.5         2.5          4.0         1.3
# 91           5.5         2.6          4.4         1.2
# 92           6.1         3.0          4.6         1.4
# 93           5.8         2.6          4.0         1.2
# 94           5.0         2.3          3.3         1.0
# 95           5.6         2.7          4.2         1.3
# 96           5.7         3.0          4.2         1.2
# 97           5.7         2.9          4.2         1.3
# 98           6.2         2.9          4.3         1.3
# 99           5.1         2.5          3.0         1.1
# 100          5.7         2.8          4.1         1.3
# 101          6.3         3.3          6.0         2.5
# 102          5.8         2.7          5.1         1.9
# 103          7.1         3.0          5.9         2.1
# 104          6.3         2.9          5.6         1.8
# 105          6.5         3.0          5.8         2.2
# 106          7.6         3.0          6.6         2.1
# 107          4.9         2.5          4.5         1.7
# 108          7.3         2.9          6.3         1.8
# 109          6.7         2.5          5.8         1.8
# 110          7.2         3.6          6.1         2.5
# 111          6.5         3.2          5.1         2.0
# 112          6.4         2.7          5.3         1.9
# 113          6.8         3.0          5.5         2.1
# 114          5.7         2.5          5.0         2.0
# 115          5.8         2.8          5.1         2.4
# 116          6.4         3.2          5.3         2.3
# 117          6.5         3.0          5.5         1.8
# 118          7.7         3.8          6.7         2.2
# 119          7.7         2.6          6.9         2.3
# 120          6.0         2.2          5.0         1.5
# 121          6.9         3.2          5.7         2.3
# 122          5.6         2.8          4.9         2.0
# 123          7.7         2.8          6.7         2.0
# 124          6.3         2.7          4.9         1.8
# 125          6.7         3.3          5.7         2.1
# 126          7.2         3.2          6.0         1.8
# 127          6.2         2.8          4.8         1.8
# 128          6.1         3.0          4.9         1.8
# 129          6.4         2.8          5.6         2.1
# 130          7.2         3.0          5.8         1.6
# 131          7.4         2.8          6.1         1.9
# 132          7.9         3.8          6.4         2.0
# 133          6.4         2.8          5.6         2.2
# 134          6.3         2.8          5.1         1.5
# 135          6.1         2.6          5.6         1.4
# 136          7.7         3.0          6.1         2.3
# 137          6.3         3.4          5.6         2.4
# 138          6.4         3.1          5.5         1.8
# 139          6.0         3.0          4.8         1.8
# 140          6.9         3.1          5.4         2.1
# 141          6.7         3.1          5.6         2.4
# 142          6.9         3.1          5.1         2.3
# 143          5.8         2.7          5.1         1.9
# 144          6.8         3.2          5.9         2.3
# 145          6.7         3.3          5.7         2.5
# 146          6.7         3.0          5.2         2.3
# 147          6.3         2.5          5.0         1.9
# 148          6.5         3.0          5.2         2.0
# 149          6.2         3.4          5.4         2.3
# 150          5.9         3.0          5.1         1.8
# 
# $na.action
# NULL
# 
# $center
# [1] TRUE
# 
# $scaled
# [1] FALSE
# 
# $means
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#          5.8          3.1          3.8          1.2 
# 
# $sd
# [1] 1 1 1 1
# 
# $n
# [1] 150
# 
# $p
# [1] 4
# 
# $group.aes
#   [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#  [58] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# [115] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# Levels: 1
# 
# $g.names
# [1] "1"
# 
# $g
# [1] 1
# 
# $Title
# NULL
# 
# $Z
#        [,1]    [,2]
# 1   -2.6841 -0.3194
# 2   -2.7141  0.1770
# 3   -2.8890  0.1449
# 4   -2.7453  0.3183
# 5   -2.7287 -0.3268
# 6   -2.2809 -0.7413
# 7   -2.8205  0.0895
# 8   -2.6261 -0.1634
# 9   -2.8864  0.5783
# 10  -2.6728  0.1138
# 11  -2.5069 -0.6451
# 12  -2.6128 -0.0147
# 13  -2.7861  0.2351
# 14  -3.2238  0.5114
# 15  -2.6448 -1.1788
# 16  -2.3860 -1.3381
# 17  -2.6235 -0.8107
# 18  -2.6483 -0.3118
# 19  -2.1998 -0.8728
# 20  -2.5880 -0.5136
# 21  -2.3103 -0.3913
# 22  -2.5437 -0.4330
# 23  -3.2159 -0.1335
# 24  -2.3027 -0.0987
# 25  -2.3558  0.0373
# 26  -2.5067  0.1460
# 27  -2.4688 -0.1310
# 28  -2.5623 -0.3677
# 29  -2.6395 -0.3120
# 30  -2.6320  0.1970
# 31  -2.5874  0.2043
# 32  -2.4099 -0.4109
# 33  -2.6489 -0.8134
# 34  -2.5987 -1.0931
# 35  -2.6369  0.1213
# 36  -2.8662 -0.0694
# 37  -2.6252 -0.5994
# 38  -2.8007 -0.2686
# 39  -2.9805  0.4880
# 40  -2.5900 -0.2290
# 41  -2.7701 -0.2635
# 42  -2.8494  0.9410
# 43  -2.9974  0.3419
# 44  -2.4056 -0.1889
# 45  -2.2095 -0.4367
# 46  -2.7145  0.2502
# 47  -2.5381 -0.5038
# 48  -2.8395  0.2279
# 49  -2.5431 -0.5794
# 50  -2.7034 -0.1077
# 51   1.2848 -0.6852
# 52   0.9325 -0.3183
# 53   1.4643 -0.5043
# 54   0.1833  0.8280
# 55   1.0881 -0.0746
# 56   0.6417  0.4182
# 57   1.0951 -0.2835
# 58  -0.7491  1.0049
# 59   1.0441 -0.2284
# 60  -0.0087  0.7231
# 61  -0.5078  1.2660
# 62   0.5117  0.1040
# 63   0.2650  0.5500
# 64   0.9849  0.1248
# 65  -0.1739  0.2549
# 66   0.9279 -0.4672
# 67   0.6603  0.3530
# 68   0.2361  0.3336
# 69   0.9447  0.5431
# 70   0.0452  0.5838
# 71   1.1163  0.0846
# 72   0.3579  0.0689
# 73   1.2982  0.3278
# 74   0.9217  0.1827
# 75   0.7149 -0.1491
# 76   0.9002 -0.3285
# 77   1.3320 -0.2444
# 78   1.5578 -0.2675
# 79   0.8133  0.1634
# 80  -0.3056  0.3683
# 81  -0.0681  0.7052
# 82  -0.1896  0.6803
# 83   0.1364  0.3140
# 84   1.3800  0.4210
# 85   0.5880  0.4843
# 86   0.8069 -0.1942
# 87   1.2207 -0.4076
# 88   0.8151  0.3720
# 89   0.2460  0.2685
# 90   0.1664  0.6819
# 91   0.4648  0.6707
# 92   0.8908  0.0345
# 93   0.2305  0.4044
# 94  -0.7045  1.0122
# 95   0.3570  0.5049
# 96   0.3319  0.2127
# 97   0.3762  0.2932
# 98   0.6426 -0.0177
# 99  -0.9065  0.7561
# 100  0.2990  0.3489
# 101  2.5312  0.0098
# 102  1.4152  0.5749
# 103  2.6167 -0.3439
# 104  1.9715  0.1797
# 105  2.3500  0.0403
# 106  3.3970 -0.5508
# 107  0.5212  1.1928
# 108  2.9326 -0.3555
# 109  2.3212  0.2438
# 110  2.9168 -0.7828
# 111  1.6618 -0.2422
# 112  1.8034  0.2156
# 113  2.1656 -0.2163
# 114  1.3462  0.7768
# 115  1.5859  0.5396
# 116  1.9045 -0.1193
# 117  1.9497 -0.0419
# 118  3.4871 -1.1757
# 119  3.7956 -0.2573
# 120  1.3008  0.7611
# 121  2.4278 -0.3782
# 122  1.1990  0.6061
# 123  3.4999 -0.4607
# 124  1.3888  0.2044
# 125  2.2754 -0.3350
# 126  2.6141 -0.5609
# 127  1.2585  0.1797
# 128  1.2911  0.1167
# 129  2.1236  0.2097
# 130  2.3880 -0.4646
# 131  2.8417 -0.3753
# 132  3.2307 -1.3742
# 133  2.1594  0.2173
# 134  1.4442  0.1434
# 135  1.7813  0.4999
# 136  3.0765 -0.6881
# 137  2.1442 -0.1401
# 138  1.9051 -0.0493
# 139  1.1693  0.1650
# 140  2.1076 -0.3723
# 141  2.3142 -0.1837
# 142  1.9223 -0.4092
# 143  1.4152  0.5749
# 144  2.5630 -0.2779
# 145  2.4187 -0.3048
# 146  1.9441 -0.1875
# 147  1.5272  0.3753
# 148  1.7643 -0.0789
# 149  1.9009 -0.1166
# 150  1.3902  0.2827
# 
# $Vr
#        [,1]   [,2]
# [1,]  0.361 -0.657
# [2,] -0.085 -0.730
# [3,]  0.857  0.173
# [4,]  0.358  0.075
# 
# $Xhat
#     [,1] [,2] [,3]  [,4]
# 1    5.1  3.5 1.40 0.214
# 2    4.7  3.2 1.46 0.240
# 3    4.7  3.2 1.31 0.175
# 4    4.6  3.1 1.46 0.240
# 5    5.1  3.5 1.36 0.197
# 6    5.5  3.8 1.68 0.326
# 7    4.8  3.2 1.36 0.196
# 8    5.0  3.4 1.48 0.246
# 9    4.4  2.9 1.39 0.209
# 10   4.8  3.2 1.49 0.250
# 11   5.4  3.7 1.50 0.252
# 12   4.9  3.3 1.52 0.262
# 13   4.7  3.1 1.41 0.219
# 14   4.3  3.0 1.08 0.083
# 15   5.7  4.1 1.29 0.163
# 16   5.9  4.2 1.48 0.243
# 17   5.4  3.9 1.37 0.198
# 18   5.1  3.5 1.44 0.227
# 19   5.6  3.9 1.72 0.345
# 20   5.2  3.7 1.45 0.233
# 21   5.3  3.5 1.71 0.342
# 22   5.2  3.6 1.50 0.255
# 23   4.8  3.4 0.98 0.037
# 24   5.1  3.3 1.77 0.367
# 25   5.0  3.2 1.75 0.358
# 26   4.8  3.2 1.64 0.312
# 27   5.0  3.4 1.62 0.305
# 28   5.2  3.5 1.50 0.254
# 29   5.1  3.5 1.44 0.230
# 30   4.8  3.1 1.54 0.271
# 31   4.8  3.1 1.58 0.288
# 32   5.2  3.6 1.62 0.305
# 33   5.4  3.9 1.35 0.189
# 34   5.6  4.1 1.34 0.186
# 35   4.8  3.2 1.52 0.264
# 36   4.9  3.4 1.29 0.167
# 37   5.3  3.7 1.41 0.213
# 38   5.0  3.5 1.31 0.176
# 39   4.4  3.0 1.29 0.168
# 40   5.1  3.4 1.50 0.254
# 41   5.0  3.5 1.34 0.187
# 42   4.2  2.6 1.48 0.249
# 43   4.5  3.1 1.25 0.151
# 44   5.1  3.4 1.66 0.323
# 45   5.3  3.6 1.79 0.375
# 46   4.7  3.1 1.48 0.246
# 47   5.3  3.6 1.50 0.252
# 48   4.7  3.1 1.37 0.199
# 49   5.3  3.7 1.48 0.244
# 50   4.9  3.4 1.42 0.223
# 51   6.8  3.4 4.74 1.608
# 52   6.4  3.2 4.50 1.509
# 53   6.7  3.3 4.92 1.686
# 54   5.4  2.4 4.06 1.328
# 55   6.3  3.0 4.68 1.584
# 56   5.8  2.7 4.38 1.461
# 57   6.4  3.2 4.65 1.570
# 58   4.9  2.4 3.29 1.007
# 59   6.4  3.1 4.61 1.556
# 60   5.4  2.5 3.88 1.251
# 61   4.8  2.2 3.54 1.113
# 62   6.0  2.9 4.21 1.391
# 63   5.6  2.6 4.08 1.336
# 64   6.1  2.9 4.62 1.562
# 65   5.6  2.9 3.65 1.156
# 66   6.5  3.3 4.47 1.497
# 67   5.9  2.7 4.38 1.463
# 68   5.7  2.8 4.02 1.309
# 69   5.8  2.6 4.66 1.579
# 70   5.5  2.6 3.90 1.260
# 71   6.2  2.9 4.73 1.606
# 72   5.9  3.0 4.08 1.333
# 73   6.1  2.7 4.93 1.689
# 74   6.1  2.8 4.58 1.543
# 75   6.2  3.1 4.34 1.444
# 76   6.4  3.2 4.47 1.497
# 77   6.5  3.1 4.86 1.658
# 78   6.6  3.1 5.05 1.737
# 79   6.0  2.9 4.48 1.503
# 80   5.5  2.8 3.56 1.118
# 81   5.4  2.5 3.82 1.228
# 82   5.3  2.6 3.71 1.183
# 83   5.7  2.8 3.93 1.272
# 84   6.1  2.6 5.01 1.726
# 85   5.7  2.7 4.35 1.447
# 86   6.3  3.1 4.42 1.474
# 87   6.6  3.3 4.73 1.606
# 88   5.9  2.7 4.52 1.519
# 89   5.8  2.8 4.02 1.308
# 90   5.5  2.5 4.02 1.310
# 91   5.6  2.5 4.27 1.416
# 92   6.1  3.0 4.53 1.521
# 93   5.7  2.7 4.03 1.312
# 94   4.9  2.4 3.33 1.023
# 95   5.6  2.7 4.15 1.365
# 96   5.8  2.9 4.08 1.334
# 97   5.8  2.8 4.13 1.356
# 98   6.1  3.0 4.31 1.428
# 99   5.0  2.6 3.11 0.932
# 100  5.7  2.8 4.07 1.333
# 101  6.8  2.8 5.93 2.107
# 102  6.0  2.5 5.07 1.750
# 103  7.0  3.1 5.94 2.111
# 104  6.4  2.8 5.48 1.919
# 105  6.7  2.8 5.78 2.044
# 106  7.4  3.2 6.57 2.375
# 107  5.2  2.1 4.41 1.476
# 108  7.1  3.1 6.21 2.223
# 109  6.5  2.7 5.79 2.049
# 110  7.4  3.4 6.12 2.185
# 111  6.6  3.1 5.14 1.776
# 112  6.4  2.7 5.34 1.862
# 113  6.8  3.0 5.58 1.959
# 114  5.8  2.4 5.05 1.740
# 115  6.1  2.5 5.21 1.808
# 116  6.6  3.0 5.37 1.873
# 117  6.6  2.9 5.42 1.895
# 118  7.9  3.6 6.54 2.360
# 119  7.4  2.9 6.97 2.540
# 120  5.8  2.4 5.00 1.723
# 121  7.0  3.1 5.77 2.041
# 122  5.9  2.5 4.89 1.675
# 123  7.4  3.1 6.68 2.419
# 124  6.2  2.8 4.98 1.712
# 125  6.9  3.1 5.65 1.989
# 126  7.2  3.2 5.90 2.094
# 127  6.2  2.8 4.87 1.664
# 128  6.2  2.9 4.88 1.671
# 129  6.5  2.7 5.61 1.976
# 130  7.0  3.2 5.72 2.020
# 131  7.1  3.1 6.13 2.189
# 132  7.9  3.8 6.29 2.253
# 133  6.5  2.7 5.65 1.989
# 134  6.3  2.8 5.02 1.728
# 135  6.2  2.5 5.37 1.875
# 136  7.4  3.3 6.27 2.250
# 137  6.7  3.0 5.57 1.957
# 138  6.6  2.9 5.38 1.878
# 139  6.2  2.8 4.79 1.631
# 140  6.8  3.2 5.50 1.926
# 141  6.8  3.0 5.71 2.015
# 142  6.8  3.2 5.33 1.857
# 143  6.0  2.5 5.07 1.750
# 144  7.0  3.0 5.91 2.097
# 145  6.9  3.1 5.78 2.043
# 146  6.7  3.0 5.39 1.882
# 147  6.1  2.7 5.13 1.775
# 148  6.5  3.0 5.26 1.826
# 149  6.6  3.0 5.37 1.872
# 150  6.2  2.7 5.00 1.719
# attr(,"scaled:center")
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#         -5.8         -3.1         -3.8         -1.2 
# 
# $ax.one.unit
#       [,1]  [,2]
# [1,]  0.64 -1.17
# [2,] -0.16 -1.35
# [3,]  1.12  0.23
# [4,]  2.67  0.56
# 
# attr(,"class")
# [1] "biplot" "PCA"

Step 3.1: samples()

# function (bp, col = ez.col, pch = 3, cex = 1, label = F, label.cex = 0.75, 
#     label.side = "bottom", connected = F, alpha = 1) 
# NULL
Argument Description
bp Object of class biplot.
col Sample colour.
pch Sample plotting character.
cex Sample character expansion.
label Logical argument, whether samples should be labelled or not, with default FALSE.

Step 3.1: samples() - continues

# function (bp, col = ez.col, pch = 3, cex = 1, label = F, label.cex = 0.75, 
#     label.side = "bottom", connected = F, alpha = 1) 
# NULL
Argument Description
label.cex Label text expansion.
label.side Side of the plotting character where label appears, with default “bottom”.
connected Logical argument, whether samples are connected in order of rows of data matrix, with default “FALSE”.
alpha Opacity, with default 1.

Step 3.1: samples() - Example

biplot(iris[,1:4]) |> PCA() |> samples(col="purple",pch=15) |> plot()

Step 3.2: axes()

# function (bp, X.names = colnames(bp$X), which = 1:bp$p, col = grey(0.7), 
#     lwd = 1, lty = 1, label.dir = "Orthog", label.col = col, 
#     label.cex = 0.75, label.dist = 0, ticks = 5, tick.col = col, 
#     tick.size = 1, tick.label = T, tick.label.col = tick.col, 
#     tick.label.cex = 0.6, tick.label.side = "left", tick.label.offset = 0.5, 
#     tick.label.pos = 1, predict.col = col, predict.lwd = lwd, 
#     predict.lty = lty, ax.names = X.names, orthogx = 0, orthogy = 0) 
# NULL
Argument Description
bp Object of class biplot.
X.names Data column names for which axes should be constructed.
which Column numbers for which axes should be constructed.
col Axis colours.
lwd Axis line widths.

Step 3.2: axes() - continues

# function (bp, X.names = colnames(bp$X), which = 1:bp$p, col = grey(0.7), 
#     lwd = 1, lty = 1, label.dir = "Orthog", label.col = col, 
#     label.cex = 0.75, label.dist = 0, ticks = 5, tick.col = col, 
#     tick.size = 1, tick.label = T, tick.label.col = tick.col, 
#     tick.label.cex = 0.6, tick.label.side = "left", tick.label.offset = 0.5, 
#     tick.label.pos = 1, predict.col = col, predict.lwd = lwd, 
#     predict.lty = lty, ax.names = X.names, orthogx = 0, orthogy = 0) 
# NULL
Argument Description
lty Axis line types.
label.dir Direction of the axis label. “Orthog”, “Hor” or “Paral”, with default “Orthog”.
label.col Colour of the axis label.
label.cex Character expansion of the axis label.
label.dist Distance of the axis label from the plot.

Step 3.2: axes() - continues

# function (bp, X.names = colnames(bp$X), which = 1:bp$p, col = grey(0.7), 
#     lwd = 1, lty = 1, label.dir = "Orthog", label.col = col, 
#     label.cex = 0.75, label.dist = 0, ticks = 5, tick.col = col, 
#     tick.size = 1, tick.label = T, tick.label.col = tick.col, 
#     tick.label.cex = 0.6, tick.label.side = "left", tick.label.offset = 0.5, 
#     tick.label.pos = 1, predict.col = col, predict.lwd = lwd, 
#     predict.lty = lty, ax.names = X.names, orthogx = 0, orthogy = 0) 
# NULL
Argument Description
ticks Indicator of the number of tick marks on each axis, with default 5.
tick.col Colour of tick marks.
tick.size Size of tick marks.
tick.label Logical whether tick marks should be labelled, with default TRUE.
tick.label.col Colour of tick mark labels.

Step 3.2: axes() - continues

# function (bp, X.names = colnames(bp$X), which = 1:bp$p, col = grey(0.7), 
#     lwd = 1, lty = 1, label.dir = "Orthog", label.col = col, 
#     label.cex = 0.75, label.dist = 0, ticks = 5, tick.col = col, 
#     tick.size = 1, tick.label = T, tick.label.col = tick.col, 
#     tick.label.cex = 0.6, tick.label.side = "left", tick.label.offset = 0.5, 
#     tick.label.pos = 1, predict.col = col, predict.lwd = lwd, 
#     predict.lty = lty, ax.names = X.names, orthogx = 0, orthogy = 0) 
# NULL
Argument Description
tick.label.cex Character expansion of of tick mark labels.
tick.label.side On which side of tick marks label should appear, with default “left”.
tick.label.offset Offset for position of tick mark labels.
tick.label.pos pos argument for text function for tick mark labels, with default 1.
predict.col Colour of lines showing orthogonal projection onto axes.

Step 3.2: axes() - continues

# function (bp, X.names = colnames(bp$X), which = 1:bp$p, col = grey(0.7), 
#     lwd = 1, lty = 1, label.dir = "Orthog", label.col = col, 
#     label.cex = 0.75, label.dist = 0, ticks = 5, tick.col = col, 
#     tick.size = 1, tick.label = T, tick.label.col = tick.col, 
#     tick.label.cex = 0.6, tick.label.side = "left", tick.label.offset = 0.5, 
#     tick.label.pos = 1, predict.col = col, predict.lwd = lwd, 
#     predict.lty = lty, ax.names = X.names, orthogx = 0, orthogy = 0) 
# NULL
Argument Description
predict.lwd Line width of lines showing orthogonal projection onto axes.
predict.lty Line type of lines showing ortghonoal projection onto axes.
ax.names User specified alternative names for variables.
orthogx Horizontal translation.
orthogy Vertical translation.

Step 3.2: axes() - Example

biplot(iris[,1:4]) |> PCA() |> axes(col="purple") |> plot()

Step 4.1: alpha.bags()

# function (bp, alpha = 0.95, which = NULL, col = ez.col, lty = 1, 
#     lwd = 1, max = 2500) 
# NULL
Argument Description
bp Object of class biplot.
alpha Value between 0 and 1 to determine coverage of bag, with default 0.95.
which Which groups or classes to be fitted with alpha bags.
col Vector of colours for the alpha bags.

Step 4.1: alpha.bags() - Example

biplot (iris[,1:4]) |> PCA(group.aes=iris[,5]) |> alpha.bags(alpha=0.95) |> plot()
# Computing 0.95 -bag for setosa 
# Computing 0.95 -bag for versicolor 
# Computing 0.95 -bag for virginica

Step 4.2: concentration.ellipse()

# function (bp, df = 2, kappa = NULL, which = NULL, alpha = 0.95, 
#     col = ez.col, lty = 1, lwd = 1, alpha.transparency = 0.5) 
# NULL
Argument Description
lty Vector of line types for the alpha bags.
lwd Vector of line widths for the alpha bags.
max Maximum number of samples to include in alpha bag calculation, with default 2500.

Step 4.2: concentration.ellipse() - Example

biplot (iris[,1:4]) |> PCA(group.aes=iris[,5]) |> concentration.ellipse(kappa=2) |> plot()
# Computing 2 -ellipse for setosa 
# Computing 2 -ellipse for versicolor 
# Computing 2 -ellipse for virginica

Step 5: legend.type()

# function (bp, samples = F, means = F, bags = F, new = FALSE, 
#     ...) 
# NULL
Argument Description
bp Object of class biplot.
samples Logical argument, whether legend should be printed for samples, with default “FALSE”.
means Logical argument, whether legend should be printed for means, with default “FALSE”.
bags Logical argument, whether legend should be printed for bags, with default “FALSE”.
new Logical argument, whether legend should appear on a new page, with default “FALSE”.

Step 5: legend.type() - Example

biplot (iris[,1:4], Title="Test biplot") |> PCA(group.aes = iris[,5]) |>
    legend.type(samples=TRUE) |> plot()

Final step: plot()

# function (x, y, ...) 
# NULL

plot(x, exp.factor = 1.2, …)